cp commands

In this guide, we focus on cp command in Linux/Unix systems. cp command – short for copy – is a command used for copying files and directories in Linux. It’s a command that is widely used both by Linux beginners and seasoned experts on a regular basis. Let’s dive in and see how this command is used.

Linux cp commands example

$ cp [options] source dest


copy a file from current directory to subdirectory

To copy a file from the present working directory to a subdirectory use the syntax below:

$ cp file directory


copy multiple file 

$ cp file1 file2 .... /path/to/directory

$ cp file1.txt file2.txt file3.txt /home/james/


copy file with verbose output

cp -v file1.txt file2.txt  /home/james


copy file interactively 

$ cp -i file1.txt /home/james


copy file with certain extension 

$ cp *.txt  /home/james


copy Directory recursively 

$ cp -R data /home/james

To copy the contents of a directory but not the directory itself, run the command as follows.

$ cp -R data/* /home/james


copy same file in multiple location

cp -v file.txt /root/;cp -v file2.txt /root/test/


copy multiple file using loop

for i in $(cat file.list);do cp -v $i /root/;done




No comments:

Post a Comment